package com.xuecheng.media.config;

import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.vod.model.v20170321.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 抽取工具类
 */
@Component
public class VodTemplate {

    @Autowired
    private DefaultAcsClient client;

    //获取上传凭证
    public CreateUploadVideoResponse createUploadVideo(String title,String filename) throws ClientException {
        CreateUploadVideoRequest request = new CreateUploadVideoRequest();
        request.setTitle(title); //标题
        request.setFileName(filename);  //文件名称
        CreateUploadVideoResponse response = client.getAcsResponse(request);
        return response;
    }

    //刷新凭证
    public RefreshUploadVideoResponse refreshUploadVideo(String videoId) throws Exception {
        RefreshUploadVideoRequest request = new RefreshUploadVideoRequest();
        //音频或视频ID
        request.setVideoId(videoId);
        RefreshUploadVideoResponse response = client.getAcsResponse(request);
        return response;
    }


    //获取播放地址
    public GetPlayInfoResponse getPlayInfo(String videoId) throws Exception {
        GetPlayInfoRequest request = new GetPlayInfoRequest();
        request.setVideoId(videoId);
        return client.getAcsResponse(request);
    }
}
